/**
 * @author Fang Lu, fanglupku@gmail.com
 * 2011-4-12
 */
package dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import controller.CrawlerConfig;

public class BaseDao {
	public static Connection getDbConnection(String dbURL, String user, String pwd){
		try {			
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			return DriverManager.getConnection(dbURL, user, pwd);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
	}
	public static Connection getTestConn(){
		try {		
			CrawlerConfig config = new CrawlerConfig("crawlerconf.test_auto");
			String dbURL = config.getDatabaseURL();
			String user = config.getDatabaseUsername();
			String pwd = config.getDatabasePwd();
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			return DriverManager.getConnection(dbURL, user, pwd);
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} 
		return null;
	}
}
